<?php

$app->hook('slim.after.router',function() use($app){
    $app->view->setData(array('mode'=>MODE));
});

$app->hook('task.before', function () use ($app, $c) {
    $projectTable = $c['Task.Table.Project'];
    $projects = $projectTable->select();
    $app->view->setData(array('projects' => $projects));
});

$app->hook('blue.before', function () use ($app, $c) {
    $categoryTable = $c['Blue.Table.Category'];
    $items = array();
    $rowset = $categoryTable->select(array('parent_id' => 0));
    foreach ($rowset as $row) {
        $cat = new \Hengha\Blue\Model\Category();
        $cat->id = $row->id;
        $cat->name = $row->name;
        $cat->children = $categoryTable->select(array('parent_id' => $row->id));
        $items[] = $cat;
    }

    $app->view->setData(array('categories' => $items));
});